package com.common.android.utils;



import com.product.android.business.ApplicationVariable;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;


/**
 * 配置项管理类
 * 
 */
public class ConfigHelper {
	public static final String GuideBefore="guidebefore";
	public static final String ReadTestDetail="ReadTestDetail";
	

	public static SharedPreferences getSharedPreferences(Context ctx,
			String PREF_NAME) {
		SharedPreferences mSettings = ctx.getSharedPreferences(PREF_NAME, 0);
		return mSettings;

	}

	public static Editor getEditor(Context ctx, String PREF_NAME) {
		SharedPreferences mSettings = ctx.getSharedPreferences(PREF_NAME, 0);
		Editor editor = mSettings.edit();
		return editor;

	}
	
	
	/*
	 * 保存key到配制文件
	 */
	public static void saveKey(Context ctx, String PREF_NAME,String key, String value) {
		SharedPreferences mSettings = ctx.getSharedPreferences(PREF_NAME, 0);
		Editor mEditor = mSettings.edit();
		mEditor.putString(key, value);
		mEditor.commit();
	}
	public static void saveBooleanKey(Context ctx, String PREF_NAME,String key, boolean value) {
		SharedPreferences mSettings = ctx.getSharedPreferences(PREF_NAME, 0);
		Editor mEditor = mSettings.edit();
		mEditor.putBoolean(key, value);
		mEditor.commit();
	}
	
	/**
	 * 保存int到  PREF_NAME文件中
	 * @param ctx
	 * @param PREF_NAME
	 * @param key
	 * @param value
	 */
	public static void saveIntKey(Context ctx, String PREF_NAME,String key, int value) {
		SharedPreferences mSettings = ctx.getSharedPreferences(PREF_NAME, 0);
		Editor mEditor = mSettings.edit();
		mEditor.putInt(key, value);
		mEditor.commit();
	}
	
	/**
	 * 从 PREF_NAME文件中取出int值
	 * @param ctx
	 * @param PREF_NAME
	 * @param key
	 * @param defValue
	 * @return
	 */
	public static int loadIntKey(Context ctx, String PREF_NAME,String key,int defValue) {
		SharedPreferences mSettings = ctx.getSharedPreferences(PREF_NAME, 0);
		return  mSettings.getInt(key, defValue);
	}
	
	/**
	 * 保存long到  PREF_NAME文件中
	 * @param ctx
	 * @param PREF_NAME
	 * @param key
	 * @param value
	 */
	public static void saveLongKey(Context ctx, String PREF_NAME,String key, long value) {
		SharedPreferences mSettings = ctx.getSharedPreferences(PREF_NAME, 0);
		Editor mEditor = mSettings.edit();
		mEditor.putLong(key, value);
		mEditor.commit();
	}
	
	/**
	 * 从 PREF_NAME文件中取出long值
	 * @param ctx
	 * @param PREF_NAME
	 * @param key
	 * @param defValue
	 * @return
	 */
	public static long loadLongKey(Context ctx, String PREF_NAME,String key,long defValue) {
		SharedPreferences mSettings = ctx.getSharedPreferences(PREF_NAME, 0);
		return  mSettings.getLong(key, defValue);
	}
	/*
	 * 从配制文件取出key
	 */
	public static String loadKey(Context ctx, String PREF_NAME,String key) {
		SharedPreferences mSettings = ctx.getSharedPreferences(PREF_NAME, 0);
		return mSettings.getString(key, "");
	}
	
	public static boolean loadBooleanKey(Context ctx, String PREF_NAME,String key) {
		SharedPreferences mSettings = ctx.getSharedPreferences(PREF_NAME, 0);
		return  mSettings.getBoolean(key, false);
	}
	
	/*
	 * 从配制文件删除key
	 */
    public static void removeKey(Context ctx, String PREF_NAME,String key) {
    	SharedPreferences mSettings = ctx.getSharedPreferences(PREF_NAME, 0);
    	Editor mEditor = mSettings.edit();
        mEditor.remove(key);
        mEditor.commit();
    }
	
	/**
	 * 
	 * @n<b>函数名称</b>     :saveGroupSetType
	 * @brief                保存key  uid_key
	 * @see
	 * @since    Ver 1.1
	 * @param  @param groupkey
	 * @param  @param value
	 * @return void
	 * @<b>作者</b>          :  zhy
	 * @<b>创建时间</b>      :  2014-3-6下午3:35:55
	 */
	public static void  saveGroupSetType(String groupkey,int value){
		ConfigHelper.saveIntKey(ApplicationVariable.INSTANCE.applicationContext, ApplicationVariable.INSTANCE.getIUser().getOapUid()+"",groupkey, value);
	}
	
	public static int  getGroupSetType(String groupkey,int defValue){
		return ConfigHelper.loadIntKey(ApplicationVariable.INSTANCE.applicationContext,ApplicationVariable.INSTANCE.getIUser().getOapUid()+"",groupkey, defValue);
	}
	
    public static void removeGroupSetKey(String key) {
    	SharedPreferences mSettings =ApplicationVariable.INSTANCE.applicationContext.getSharedPreferences(ApplicationVariable.INSTANCE.getIUser().getOapUid()+"", 0);
    	Editor mEditor = mSettings.edit();
        mEditor.remove(key);
        mEditor.commit();
    }

}
